package team.sun.sss.controller.staff;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import team.sun.sss.dao.staff.*;
import team.sun.sss.pojo.staff.Staff;
import team.sun.sss.pojo.student.Student1;
import team.sun.sss.service.staff.StaffService;
import team.sun.sss.service.staff.StaffServiceImpl;
import team.sun.sss.service.user.UserServiceImpl;

import java.util.List;


@Controller
public class StaffController {
    @Autowired
    StaffServiceImpl staffService;
    @Autowired
    UserServiceImpl userService;
    @Autowired
    StaffCertificateDao staffCertificateDao;
    @Autowired
    StaffCourseDao staffCourseDao;
    @Autowired
    StaffRewardDao staffRewardDao;
    @Autowired
    StaffThesisDao staffThesisDao;
    @Autowired
    StaffTrainDao staffTrainDao;
    @Autowired
    StaffTakeStudentDao staffTakeStudentDao;
    @Autowired
    StaffThesisDao StaffThesisDao;
    @Autowired
    StaffDao staffDao;

    //政工管理
    @GetMapping("/staff_info")
    public String staff_info(Model model,@RequestParam(required = false,defaultValue="1",value="pageNum")Integer pageNum,
                             @RequestParam(defaultValue="5",value="pageSize")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        try {
            List<Staff> staffList = staffService.getStaffList();
            model.addAttribute("staff_list",staffList);
            PageInfo<Staff> pageInfo = new PageInfo<Staff>(staffList,pageSize);
            model.addAttribute("pageInfo",pageInfo);
        }finally {
            PageHelper.clearPage();
        }
        return "staff/staff_info";
    }
    //政工管理详情
    @GetMapping("/staff_detail/{sta_num}")
    public String staff_detail(@PathVariable(name = "sta_num") String sta_num,Model model){
        model.addAttribute("staffCertificateList",staffCertificateDao.getStaffCertificateById(sta_num));
        model.addAttribute("staffCourseList",staffCourseDao.getStaffCourseById(sta_num));
        model.addAttribute("staffRewardList",staffRewardDao.getStaffRewardById(sta_num));
        model.addAttribute("staffCertificateList",staffCertificateDao.getStaffCertificateById(sta_num));
        model.addAttribute("staffTrainList",staffTrainDao.getStaffTrainById(sta_num));
        model.addAttribute("staffTakeStudentList",staffTakeStudentDao.getStaffTakeStudentById(sta_num));
        model.addAttribute("StaffThesisList",StaffThesisDao.getStaffThesisById(sta_num));
        model.addAttribute("staff",staffDao.getStaffById(sta_num));
        return "staff/staff_detail";
    }
    //政工管理修改界面跳转
    @GetMapping("/staff_update/{sta_num}")
    public String staff_update_page(@PathVariable(name = "sta_num") String sta_num,Model model){
        model.addAttribute("staffCertificateList",staffCertificateDao.getStaffCertificateById(sta_num));
        model.addAttribute("staffCourseList",staffCourseDao.getStaffCourseById(sta_num));
        model.addAttribute("staffRewardList",staffRewardDao.getStaffRewardById(sta_num));
        model.addAttribute("staffCertificateList",staffCertificateDao.getStaffCertificateById(sta_num));
        model.addAttribute("staffTrainList",staffTrainDao.getStaffTrainById(sta_num));
        model.addAttribute("staffTakeStudentList",staffTakeStudentDao.getStaffTakeStudentById(sta_num));
        model.addAttribute("StaffThesisList",StaffThesisDao.getStaffThesisById(sta_num));
        model.addAttribute("staff",staffDao.getStaffById(sta_num));
        return "staff/staff_update";
    }

    //政工管理修改界面跳转
    @GetMapping("/staff_update_teacher/{sta_num}")
    public String staff_update_teacher_page(@PathVariable(name = "sta_num") String sta_num,Model model){
        model.addAttribute("staffCertificateList",staffCertificateDao.getStaffCertificateById(sta_num));
        model.addAttribute("staffCourseList",staffCourseDao.getStaffCourseById(sta_num));
        model.addAttribute("staffRewardList",staffRewardDao.getStaffRewardById(sta_num));
        model.addAttribute("staffCertificateList",staffCertificateDao.getStaffCertificateById(sta_num));
        model.addAttribute("staffTrainList",staffTrainDao.getStaffTrainById(sta_num));
        model.addAttribute("staffTakeStudentList",staffTakeStudentDao.getStaffTakeStudentById(sta_num));
        model.addAttribute("StaffThesisList",StaffThesisDao.getStaffThesisById(sta_num));
        model.addAttribute("staff",staffDao.getStaffById(sta_num));
        return "staff/staff_update_teacher";
    }
    //政工管理修改功能
    @PostMapping("/staff_update")
    public String staff_update(@ModelAttribute(value = "staff") Staff staff){
        staffDao.updateStaff(staff);
        return "redirect:/staff_update/"+staff.getStaNum();
    }
    //政工管理修改功能
    @PostMapping("/staff_update1")
    public String staff_update1(@ModelAttribute(value = "staff") Staff staff){
        staffDao.updateStaff(staff);
        return "redirect:/staff_update_teacher/"+staff.getStaNum();
    }

    //政工管理禁用
    @GetMapping("/user_stop/{id}")
    public String userStop(@PathVariable(name = "id") String id){
        userService.userStop(id);
        staffService.userStop(id);
        return "redirect:/staff_info";
    }
    //政工管理启用
    @GetMapping("/user_start/{id}")
    public String userStart(@PathVariable(name = "id") String id){
        userService.userStart(id);
        staffService.userStart(id);
        return "redirect:/staff_info";
    }
}
